#include<stdio.h>
#include<stdlib.h>
typedef int SortTypeData;


void InsertSort(SortTypeData* a, int n)
{
	for (int i = 0; i < n-1; i++)
	{
		int end = i;
		SortTypeData tmp = a[end + 1];
		while (end >= 0)
		{
			if (a[end] > tmp)
			{
				a[end + 1] = a[end];
				end--;
			}
			else
			{
				break;
			}
		}
		a[end + 1] = tmp;
	}
}

void ShellSort(SortTypeData* a, int n)
{
	int gap = n;
	while (gap > 1)
	{
		gap = gap / 3 + 1;
		for (int i = 0; i < n - gap; i++)
		{
			int end = i;
			SortTypeData tmp = a[end + gap];
			while (end >= 0)
			{
				if (a[end] > tmp)
				{
					a[end + gap] = a[end];
					end-=gap;
				}
				else
				{
					break;
				}
			}
			a[end + gap] = tmp;
		}
	}
}

int main()
{
	int a[] = { 1,2,6,0,2,8,5,4,2,3,1 };
	InsertSort(a, sizeof(a) / sizeof(int));
	int b[] = { 1,2,6,0,2,8,5,4,2,5,6,8,0,2,4,6,5,3,1 };
	ShellSort(b, sizeof(b) / sizeof(int));
	for (int i = 0; i < 11; i++)
	{
		printf("%d ", a[i]);
	}
	printf("\n");
	for (int i = 0; i < 19; i++)
	{
		printf("%d ", b[i]);
	}
	return 0;
}